package com.qen;

import com.qen.fx.ViewIndex;
import com.qen.fx.tools.MenuTools;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Scene;
import javafx.scene.control.Control;
import javafx.scene.control.SkinBase;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class App extends Application {

    public static Stage stageFinal = null;
    public static AnchorPane rootPane;

    @Override
    public void start(Stage stage) throws IOException {
        stageFinal = stage;
        stage.setTitle(ViewIndex.title);
        App.replaceSceneContent(ViewIndex.index);
        stage.show();
    }

    public static Initializable replaceSceneContent(String fxml) {

        FXMLLoader loader = new FXMLLoader();
        InputStream in = App.class.getResourceAsStream(fxml);
        loader.setBuilderFactory(new JavaFXBuilderFactory());
        loader.setLocation(App.class.getResource(fxml));
        try {
            AnchorPane page = (AnchorPane) loader.load(in);
            Scene scene = new Scene(page, ViewIndex.WindowWidth, ViewIndex.WindowHeight);
            rootPane = (AnchorPane) scene.getRoot();
            stageFinal.setScene(scene);
            stageFinal.sizeToScene();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return (Initializable) loader.getController();
    }

    public static void main(String[] args) {
        launch();
    }
}